

 var http =  require("http");
 var url = require('url');
 var fs = require("fs");

 http.createServer(function (req,res) {
     var urlObj =  url.parse(req.url,true);
     console.log(urlObj.pathname);
     //输出html
     if(urlObj.pathname=='/ajax.html'){
         fs.createReadStream('./ajax.html').pipe(res);
     }else if(urlObj.pathname=='/ajaxpathing'){
         if(req.method=='GET'){
             // console.log(urlObj.query);
             // res.end(urlObj.query.name);
         }else if(req.method=='POST'){
             req.on('data',function (chunk) {
                 var str = chunk.toString();
                 res.end(str);
             })
         }
     }else if(urlObj.pathname!='/favicon.ico'){
         fs.createReadStream('.'+urlObj.pathname).pipe(res);
     }

 }).listen(8080);












